package com.carrent.sxt.servlet;


import com.carrent.sxt.utils.ZXingCodeEncodeUtils;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author : 虎虎
 * @date :2020/9/17 13:41
 */
@WebServlet("/codeLogo")
public class CodeLogoServlet extends HttpServlet {
    private static final long serialVersionId = 1L;
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        InputStream logoStream = ZXingCodeEncodeUtils.class.getClassLoader().getResourceAsStream("宝马三系.jpg");
        BufferedImage codeImg = ZXingCodeEncodeUtils.returnZXingCodeWithLogo("阳虎的图片da's'da's'dadasdasdasdasdasdadasdas",300,300,logoStream);
        ServletOutputStream outputStream = resp.getOutputStream();
        ImageIO.write(codeImg,"JPEG",outputStream);
        outputStream.close();
    }


}